<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="预付" prop="payAdvancepay">
        <el-input
          v-model="queryParams.payAdvancepay"
          placeholder="请输入预付"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="预付支付流水号" prop="payAdvancepaycode">
        <el-input
          v-model="queryParams.payAdvancepaycode"
          placeholder="请输入预付支付流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="账单" prop="payBill">
        <el-input
          v-model="queryParams.payBill"
          placeholder="请输入账单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实付" prop="payActualpay">
        <el-input
          v-model="queryParams.payActualpay"
          placeholder="请输入实付"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="退款/补差价" prop="payDifference">
        <el-input
          v-model="queryParams.payDifference"
          placeholder="请输入退款/补差价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最终支付" prop="payFinalpay">
        <el-input
          v-model="queryParams.payFinalpay"
          placeholder="请输入最终支付"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最终支付流水号" prop="payFinalpaycode">
        <el-input
          v-model="queryParams.payFinalpaycode"
          placeholder="请输入最终支付流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="订单预付支付是否完成" prop="payStatus">
        <el-select v-model="queryParams.payStatus" placeholder="请选择订单预付支付是否完成" clearable>
          <el-option
            v-for="dict in dict.type.service_pay_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="订单最终支付是否完成" prop="payStatusfinish">
        <el-select v-model="queryParams.payStatusfinish" placeholder="请选择订单最终支付是否完成" clearable>
          <el-option
            v-for="dict in dict.type.service_pay_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="创建者" prop="payCreateBy">
        <el-input
          v-model="queryParams.payCreateBy"
          placeholder="请输入创建者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangePayCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="更新者" prop="payUpdateBy">
        <el-input
          v-model="queryParams.payUpdateBy"
          placeholder="请输入更新者"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="更新时间">
        <el-date-picker
          v-model="daterangePayUpdateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="启用标志" prop="payUseFlag">
        <el-select v-model="queryParams.payUseFlag" placeholder="请选择启用标志" clearable>
          <el-option
            v-for="dict in dict.type.service_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="删除标志" prop="payDelFlag">
        <el-select v-model="queryParams.payDelFlag" placeholder="请选择删除标志" clearable>
          <el-option
            v-for="dict in dict.type.service_yes_no"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="备注" prop="payRemark">
        <el-input
          v-model="queryParams.payRemark"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['service:pay:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['service:pay:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['service:pay:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['service:pay:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="payList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="支付信息表主键ID" align="center" prop="payId" />
      <el-table-column label="预付" align="center" prop="payAdvancepay" />
      <el-table-column label="预付支付流水号" align="center" prop="payAdvancepaycode" />
      <el-table-column label="预付方式" align="center" prop="payAdvancepaytype" />
      <el-table-column label="账单" align="center" prop="payBill" />
      <el-table-column label="实付" align="center" prop="payActualpay" />
      <el-table-column label="退款/补差价" align="center" prop="payDifference" />
      <el-table-column label="最终支付" align="center" prop="payFinalpay" />
      <el-table-column label="最终支付流水号" align="center" prop="payFinalpaycode" />
      <el-table-column label="最终支付方式" align="center" prop="payFinalpaytype" />
      <el-table-column label="订单预付支付是否完成" align="center" prop="payStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.service_pay_yes_no" :value="scope.row.payStatus"/>
        </template>
      </el-table-column>
      <el-table-column label="订单最终支付是否完成" align="center" prop="payStatusfinish">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.service_pay_yes_no" :value="scope.row.payStatusfinish"/>
        </template>
      </el-table-column>
      <el-table-column label="创建者" align="center" prop="payCreateBy" />
      <el-table-column label="创建时间" align="center" prop="payCreateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payCreateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新者" align="center" prop="payUpdateBy" />
      <el-table-column label="更新时间" align="center" prop="payUpdateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payUpdateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="启用标志" align="center" prop="payUseFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.service_yes_no" :value="scope.row.payUseFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="删除标志" align="center" prop="payDelFlag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.service_yes_no" :value="scope.row.payDelFlag"/>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="payRemark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['service:pay:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['service:pay:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改支付信息表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="预付" prop="payAdvancepay">
          <el-input v-model="form.payAdvancepay" placeholder="请输入预付" />
        </el-form-item>
        <el-form-item label="预付支付流水号" prop="payAdvancepaycode">
          <el-input v-model="form.payAdvancepaycode" placeholder="请输入预付支付流水号" />
        </el-form-item>
        <el-form-item label="账单" prop="payBill">
          <el-input v-model="form.payBill" placeholder="请输入账单" />
        </el-form-item>
        <el-form-item label="实付" prop="payActualpay">
          <el-input v-model="form.payActualpay" placeholder="请输入实付" />
        </el-form-item>
        <el-form-item label="退款/补差价" prop="payDifference">
          <el-input v-model="form.payDifference" placeholder="请输入退款/补差价" />
        </el-form-item>
        <el-form-item label="最终支付" prop="payFinalpay">
          <el-input v-model="form.payFinalpay" placeholder="请输入最终支付" />
        </el-form-item>
        <el-form-item label="最终支付流水号" prop="payFinalpaycode">
          <el-input v-model="form.payFinalpaycode" placeholder="请输入最终支付流水号" />
        </el-form-item>
        <el-form-item label="订单预付支付是否完成" prop="payStatus">
          <el-select v-model="form.payStatus" placeholder="请选择订单预付支付是否完成">
            <el-option
              v-for="dict in dict.type.service_pay_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="订单最终支付是否完成" prop="payStatusfinish">
          <el-select v-model="form.payStatusfinish" placeholder="请选择订单最终支付是否完成">
            <el-option
              v-for="dict in dict.type.service_pay_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建者" prop="payCreateBy">
          <el-input v-model="form.payCreateBy" placeholder="请输入创建者" />
        </el-form-item>
        <el-form-item label="创建时间" prop="payCreateTime">
          <el-date-picker clearable
            v-model="form.payCreateTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择创建时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="更新者" prop="payUpdateBy">
          <el-input v-model="form.payUpdateBy" placeholder="请输入更新者" />
        </el-form-item>
        <el-form-item label="更新时间" prop="payUpdateTime">
          <el-date-picker clearable
            v-model="form.payUpdateTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择更新时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="启用标志" prop="payUseFlag">
          <el-select v-model="form.payUseFlag" placeholder="请选择启用标志">
            <el-option
              v-for="dict in dict.type.service_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="删除标志" prop="payDelFlag">
          <el-select v-model="form.payDelFlag" placeholder="请选择删除标志">
            <el-option
              v-for="dict in dict.type.service_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="payRemark">
          <el-input v-model="form.payRemark" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPay, getPay, delPay, addPay, updatePay } from "@/api/service/pay";

export default {
  name: "Pay",
  dicts: ['service_yes_no', 'service_pay_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 支付信息表表格数据
      payList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 备注时间范围
      daterangePayCreateTime: [],
      // 备注时间范围
      daterangePayUpdateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        payAdvancepay: null,
        payAdvancepaycode: null,
        payAdvancepaytype: null,
        payBill: null,
        payActualpay: null,
        payDifference: null,
        payFinalpay: null,
        payFinalpaycode: null,
        payFinalpaytype: null,
        payStatus: null,
        payStatusfinish: null,
        payCreateBy: null,
        payCreateTime: null,
        payUpdateBy: null,
        payUpdateTime: null,
        payUseFlag: null,
        payDelFlag: null,
        payRemark: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        payStatus: [
          { required: true, message: "订单预付支付是否完成不能为空", trigger: "change" }
        ],
        payStatusfinish: [
          { required: true, message: "订单最终支付是否完成不能为空", trigger: "change" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询支付信息表列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangePayCreateTime && '' != this.daterangePayCreateTime) {
        this.queryParams.params["beginPayCreateTime"] = this.daterangePayCreateTime[0];
        this.queryParams.params["endPayCreateTime"] = this.daterangePayCreateTime[1];
      }
      if (null != this.daterangePayUpdateTime && '' != this.daterangePayUpdateTime) {
        this.queryParams.params["beginPayUpdateTime"] = this.daterangePayUpdateTime[0];
        this.queryParams.params["endPayUpdateTime"] = this.daterangePayUpdateTime[1];
      }
      listPay(this.queryParams).then(response => {
        this.payList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        payId: null,
        payAdvancepay: null,
        payAdvancepaycode: null,
        payAdvancepaytype: null,
        payBill: null,
        payActualpay: null,
        payDifference: null,
        payFinalpay: null,
        payFinalpaycode: null,
        payFinalpaytype: null,
        payStatus: null,
        payStatusfinish: null,
        payCreateBy: null,
        payCreateTime: null,
        payUpdateBy: null,
        payUpdateTime: null,
        payUseFlag: null,
        payDelFlag: null,
        payRemark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangePayCreateTime = [];
      this.daterangePayUpdateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.payId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加支付信息表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const payId = row.payId || this.ids
      getPay(payId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改支付信息表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.payId != null) {
            updatePay(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPay(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const payIds = row.payId || this.ids;
      this.$modal.confirm('是否确认删除支付信息表编号为"' + payIds + '"的数据项？').then(function() {
        return delPay(payIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('service/pay/export', {
        ...this.queryParams
      }, `pay_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
